package com.neusoft.bizcore.notice.notification.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.neusoft.bizcore.notice.notification.dto.NoticeTemplateAttachmentDTO;
import com.neusoft.bizcore.notice.notification.service.NoticeTemplateAttachmentService;
import com.neusoft.bizcore.web.dto.result.ResultDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "通知模板附件")
@RestController
@RequestMapping(value = "/api/w/noticeTemplateAttachment")
public class NoticeTemplateAttachmentController {

    @Autowired
    private NoticeTemplateAttachmentService noticeTemplateAttachmentService;

    @ApiOperation("上传通知模板附件")
    @PostMapping("/upload/{id}")
    public ResultDTO<NoticeTemplateAttachmentDTO> upload(@RequestParam("file") final MultipartFile file,
            @PathVariable final Long id) {
        final NoticeTemplateAttachmentDTO result = this.noticeTemplateAttachmentService.create(file, id);
        return ResultDTO.success(result);
    }

    @ApiOperation("通知模板附件详情")
    @GetMapping("/{id}")
    public ResultDTO<NoticeTemplateAttachmentDTO> details(@PathVariable final Long id) {
        final NoticeTemplateAttachmentDTO dto = this.noticeTemplateAttachmentService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除通知模板附件")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.noticeTemplateAttachmentService.delete(id);
        return ResultDTO.success();
    }

    @ApiOperation("修改通知模板附件")
    @PutMapping("/{id}")
    public ResultDTO<NoticeTemplateAttachmentDTO> update(@PathVariable final Long id,
            @RequestBody final NoticeTemplateAttachmentDTO dto) {
        final NoticeTemplateAttachmentDTO result = this.noticeTemplateAttachmentService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("下载文件")
    @GetMapping("/download/{id}")
    public void download(@PathVariable final Long id, final HttpServletResponse response) {
        this.noticeTemplateAttachmentService.download(id, response);
    }

}
